package com.java1412;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author java1412
 * @since 2023-06-06 15:44:03
 */
@SpringBootApplication
@EnableEurekaClient     // 开启eureka客户端
@EnableDiscoveryClient      // 开启服务发现的客户端，因为将来服务消费者需要去注册中心中检索需要调用服务提供者
@EnableHystrix          // 开启断路器
public class ServiceRibbonApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceRibbonApplication.class, args);
    }

    // 向IOC容器中注册restTemplate,并且加@LoadBalanced——负载均衡
    @Bean
    @LoadBalanced   // 负载均衡
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
